{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Autokeras_Titanic.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "iGEzMrP7DzOO",
        "colab_type": "text"
      },
      "source": [
        "First install autokeras from pip"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eY35wv7Uyvbz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install autokeras"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jSoV8IOlFlke",
        "colab_type": "text"
      },
      "source": [
        "Now install Tensorflow GPU"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C3GQpVLrFpCM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install tensorflow-gpu==2.1.0"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4PCynrASD_hA",
        "colab_type": "text"
      },
      "source": [
        "import autokeras"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1IMvNhwYynLx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from tensorflow.keras.datasets import mnist\n",
        "\n",
        "import autokeras as ak"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TdSaPDJCECTQ",
        "colab_type": "text"
      },
      "source": [
        "Prepare the dataset.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "grv77LqxzIqG",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
        "print(x_train.shape)  # (60000, 28, 28)\n",
        "print(y_train.shape)  # (60000,)\n",
        "print(y_train[:3])  # array([7, 2, 1], dtype=uint8)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CB2E2iYqLAfO",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "clf = ak.ImageClassifier(max_trials=3)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sB-dvwNrEHTf",
        "colab_type": "text"
      },
      "source": [
        "fit dataset to model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LtCkQMa6DlJY",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "clf.fit(x_train, y_train, epochs=10)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7davBFSIEKJG",
        "colab_type": "text"
      },
      "source": [
        "get accuracy from trained model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yjxyIzarDofC",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "print('Accuracy: {accuracy}'.format(\n",
        "    accuracy=clf.evaluate(x_test, y_test)))"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}